home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / reve / get.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  9.9 KB  |  277 lines

  1.  
  2. /*  @(#)get.c 1.3 91/11/13
  3.  *
  4.  *  Various extraction routines used by reve.
  5.  *
  6.  *  Copyright (C) 1990, 1991 - Rich Burridge & Yves Gallot.
  7.  *  All rights reserved.
  8.  *
  9.  *  Permission is granted to copy this source, for redistribution
  10.  *  in source form only, provided the news headers in "substantially
  11.  *  unaltered format" are retained, the introductory messages are not
  12.  *  removed, and no monies are exchanged.
  13.  *
  14.  *  Permission is also granted to copy this source, without the
  15.  *  news headers, for the purposes of making an executable copy by
  16.  *  means of compilation, provided that such copy will not be used
  17.  *  for the purposes of competition in any othello tournaments, without
  18.  *  prior permission from the authors.
  19.  *
  20.  *  No responsibility is taken for any errors on inaccuracies inherent
  21.  *  either to the comments or the code of this program, but if reported
  22.  *  (see README file), then an attempt will be made to fix them.
  23.  */
  24.  
  25. #include "reve.h"
  26. #include "extern.h"
  27. #include <ctype.h>
  28.  
  29.  
  30. int
  31. get_bool_resource(rtype, boolval)   /* Get boolean resource from the server. */
  32. enum res_type rtype ;
  33. int *boolval ;
  34. {
  35.   char *val, tempstr[MAXLINE] ;
  36.   int len, n ;
  37.  
  38.   if ((val = get_resource(rtype)) == NULL) return(0) ;
  39.   STRCPY(tempstr, val) ;
  40.   len = strlen(tempstr) ;
  41.   for (n = 0; n < len; n++)
  42.     if (isupper(tempstr[n])) tempstr[n] = tolower(tempstr[n]) ;
  43.   if (EQUAL(tempstr, "true")) *boolval = TRUE ;
  44.   else                        *boolval = FALSE ;
  45.   return(1) ;
  46. }
  47.  
  48.  
  49. /*  Search through the command line options to see if a -display <display>
  50.  *  has been given. We can't process the command line arguments first,
  51.  *  (using get_options()), because the SunView and XView versions, are
  52.  *  capable of having a lot of generic command line arguments which would
  53.  *  be a pain to handle. The init_graphics() routine will strip those off,
  54.  *  but the X11 version, needs the display name.
  55.  */
  56.  
  57. void
  58. get_display(argc, argv)
  59. int argc ;
  60. char *argv[] ;
  61. {
  62.   INC ;
  63.   while (argc > 0)
  64.     {
  65.       if (argv[0][0] == '-' && EQUAL(argv[0], "-display"))
  66.         {
  67.           INC ;               /* X11 display information. */
  68.           read_str(&display, *argv) ;
  69.           return ;
  70.         }
  71.       INC ;
  72.     }
  73. }
  74.  
  75.  
  76. int
  77. get_int_resource(rtype, intval)   /* Get integer resource from the server. */
  78. enum res_type rtype ;
  79. int *intval ;
  80. {
  81.   char *val ;
  82.  
  83.   if ((val = get_resource(rtype)) == NULL) return(0) ;
  84.   *intval = atoi(val) ;
  85.   return(1) ;
  86. }
  87.  
  88.  
  89. void
  90. get_options(argc, argv)   /* Read and process command line options. */
  91. int argc ;
  92. char *argv[] ;
  93. {
  94.   char next[MAXLINE] ;    /* The next command line parameter. */
  95.   int i ;
  96.  
  97.   INC ;
  98.   while (argc > 0)
  99.     {
  100.       if (argv[0][0] == '-')
  101.         switch (argv[0][1])
  102.           {
  103.             case 'a' : /* Allow computer glide and piece dragging. */
  104.                        if (EQUAL(argv[0], "-animate")) ANIMATION = TRUE ;
  105.                        break ;
  106.             case 'b' : if (EQUAL(argv[0], "-bestmove")) DO_BESTMOVE = TRUE ;
  107.                        else if (EQUAL(argv[0], "-black")) isblack = 1 ;
  108.                        break ;
  109.             case 'c' : if (EQUAL(argv[0], "-clock")) DO_CLOCK = TRUE ;
  110.                        break ;
  111.             case 'd' :      if (EQUAL(argv[0], "-debug")) debug = TRUE ;
  112.                        else if (EQUAL(argv[0], "-display"))
  113.                          {
  114.                            INC ;              /* Already processed. */
  115.                          }
  116.                        else
  117.                          { 
  118.                            INC ;
  119.                            getparam(next, argv, "-d needs difficulty") ;
  120.                            level = atoi(next) ;
  121.                            if (level < 1 || level > MAXDIFF)
  122.                              level = INIT_DEPTH ;
  123.                            items[(int) DIFF_CHOICE].value = level - 1 ;
  124.                            old_diffval = level-1 ;
  125.                          }
  126.                        break ;
  127.             case 'e' : INC ;
  128.                        getparam(edgefile, argv, "-e needs an edgetable file") ;
  129.                        break ;
  130.             case 'g' : INC ;                 /* X11 geometry information. */
  131.                        getparam(geometry, argv,
  132.                                 "-g needs geometry information") ;
  133.                        break ;
  134.             case 'h' : if (EQUAL(argv[0], "-help")) help_showing = TRUE ;
  135.                        else
  136.                          { 
  137.                            INC ;
  138.                            getparam(helpfile, argv, "-h needs a help file") ;
  139.                          }
  140.                        break ;
  141.             case 'i' : inv_video = 1 ;       /* Display in inverse video. */
  142.                        break ;
  143.             case 'l' :      if (EQUAL(argv[0], "-last")) DO_LAST = TRUE ;
  144.                        else if (EQUAL(argv[0], "-log"))  saveres = TRUE ;
  145.                        else if (EQUAL(argv[0], "-load"))
  146.                          {
  147.                            INC ;             /* Reve game file to load. */
  148.                            getparam(gamefile, argv, "-l needs a game file") ;
  149.                            loadgame = 1 ;        /* Game file to load. */
  150.                          }
  151.                        break ;
  152.             case 'm' : monochrome = 1 ;      /* Force display to mono. */
  153.                        iscolor = 0 ;
  154.                        break ;
  155.             case 'n' :      if (EQUAL(argv[0], "-notes")) SHOW_NOTES = TRUE ;
  156.                        else if (EQUAL(argv[0], "-number")) DO_NUMBER = TRUE ;
  157.                        break ;
  158.             case 'o' : if (EQUAL(argv[0], "-opponent"))
  159.                        if (*(argv+1) != NULL && argv[1][0] != '-')
  160.                          {
  161.                            INC ;
  162.                            opponent = *argv ;
  163.                            play_computer = 0 ;
  164.                          }
  165.                        break ;
  166.             case 'p' : if (EQUAL(argv[0], "-props")) props_showing = TRUE ;
  167.                        break ;
  168.             case 'q' : if (EQUAL(argv[0], "-quick")) QUICKGAME = TRUE ;
  169.                        break ;
  170.             case 'r' : INC ;
  171.                        getparam(reveproc, argv,
  172.                                 "-r needs a reve_proc pathname") ;
  173.                        break ;
  174.             case '?' :
  175.             case 'v' : usage() ;
  176.  
  177.             case 'w' : if (EQUAL(argv[0], "-white")) iswhite = 1 ;
  178.                        break ;
  179.  
  180. /*  SunView windowing arguments. -Wp, -WP and -Wi are used in the X11
  181.  *  implementation to initially position the window and icon.
  182.  */
  183.  
  184.             case 'W' : switch (argv[0][2])
  185.                          {
  186.                            case 'H' : break ;   /* -WH, no sub-args follow */
  187.                            case 'i' : iconic = 1 ;
  188.                                       break ;   /* -Wi, start as an icon. */
  189.                            case 'g' :           /* -Wg, set default color. */
  190.                            case 'n' : break ;   /* -Wn, no label at all */
  191.                            case 'h' :           /* -Wh, height */
  192.                            case 'I' :           /* -WI "icon filename" */
  193.                            case 'l' :           /* -Wl "some window label" */
  194.                            case 'L' :           /* -Wl "some icon label" */
  195.                            case 't' :           /* Font filename */
  196.                            case 'T' :           /* Icon font filename */
  197.                            case 'w' : INC ;     /* Width, in columns. */
  198.                                       break ;
  199.                            case 'p' : INC ;     /* -Wp xnum ynum */
  200.                                       getparam(next, argv,
  201.                                                "-Wp needs x coordinate") ;
  202.                                       wx = atoi(next) ;
  203.                                       INC ;
  204.                                       getparam(next, argv,
  205.                                                "-Wp needs y coordinate") ;
  206.                                       wy = atoi(next) ;
  207.                                       posspec = 1 ;
  208.                                       break ;
  209.                            case 'P' : INC ;      /* -WP xnum ynum */
  210.                                       getparam(next, argv,
  211.                                                "-WP needs x coordinate") ;
  212.                                       ix = atoi(next) ;
  213.                                       INC ;
  214.                                       getparam(next, argv,
  215.                                                "-WP needs y coordinate") ;
  216.                                       iy = atoi(next) ;
  217.                                       break ;
  218.                            case 's' : INC ; INC ;  /* -Ws xnum ynum */
  219.                                       break ;
  220.                            case 'b' :              /* -Wb r g b (bg color spec)
  221. */
  222.                            case 'f' : INC ; INC ; INC ;  /* Same, fg color */
  223.                                       break ;
  224.                            default :  FPRINTF(stderr,"%s: -W%c unknown argument\n",
  225.                                                       progname, argv[0][2]) ;
  226.                                       break ;
  227.                          }
  228.                        break ;
  229.             case 'x' : if (EQUAL(argv[0], "-xdebug")) xdebug = TRUE ;
  230.                        break ;
  231.             default  : usage() ;
  232.           }
  233.       INC ;
  234.     }
  235. }
  236.  
  237.  
  238. int
  239. get_str_resource(rtype, strval)   /* Get a string resource from the server. */
  240. enum res_type rtype ;
  241. char *strval ;
  242. {
  243.   char *val ;
  244.    
  245.   if ((val = get_resource(rtype)) == NULL) return(0) ;
  246.   STRCPY(strval, val) ;
  247.   return(1) ;
  248. }
  249.  
  250.  
  251. void
  252. getparam(s, argv, errmes)
  253. char *s, *argv[], *errmes ;
  254. {
  255.   if (*argv != NULL && argv[0][0] != '-') STRCPY(s, *argv) ;
  256.   else
  257.     { 
  258.       FPRINTF(stderr,"%s: %s as next argument.\n", progname, errmes) ;
  259.       exit(1) ;
  260.     }
  261. }
  262.  
  263.  
  264. char *
  265. getuserhost()
  266. {
  267.   char namehost[MAXLINE], *name, host[MAXLINE] ;
  268.   int len ;
  269.  
  270.   name = getlogin() ;
  271.   if (name == NULL) name = "unknown" ;
  272.   len = MAXLINE ;
  273.   gethostname(host, &len) ;
  274.   SPRINTF(namehost, "%s@%s", name, host) ;
  275.   return(namehost) ;
  276. }
  277.